import { defineStore } from 'pinia'
import { getYQDataRequest } from '@/service/userManage'

export const useYQData = defineStore('YQData', {
  state: () => {
    return {
      YQData: {} as any,
      provincesMap: {} as any,
      chinaMap: {} as any
    }
  },
  getters: {
    mapArrays: (state) => {
      return Object.keys(state.provincesMap).map((key) => {
        // return { name: key, value: state.provincesMap[key].nowConfirm }
        return { name: key, value: state.provincesMap[key].nowConfirm }
      })
    },
    dataArr: (state) => {
      return [
        {
          titleB: '累计确诊',
          titleS: '今日新增确诊',
          numB: state.chinaMap.confirm,
          numS: state.chinaMap.confirmAdd
        },
        {
          titleB: '累计死亡',
          titleS: '今日新增死亡',
          numB: state.chinaMap.dead,
          numS: state.chinaMap.deadAdd
        },
        {
          titleB: '累计本地确诊',
          titleS: '今日新增本地确诊',
          numB: state.chinaMap.localConfirm,
          numS: state.chinaMap.localConfirmAdd
        },
        {
          titleB: '现有确诊',
          titleS: '治愈人数',
          numB: state.chinaMap.nowConfirm,
          numS: state.chinaMap.heal
        },
        {
          titleB: '现有本土无症状',
          titleS: '新增本土无症状',
          numB: state.chinaMap.nowLocalWzz,
          numS: state.chinaMap.localWzzAdd
        }
      ]
    }
  },
  actions: {
    async getYiQingData() {
      const resoult = await getYQDataRequest()
      this.YQData = resoult.data
      this.provincesMap = resoult.data.provincesMap
      this.chinaMap = resoult.data.chinaMap
    }
  }
})
